package v3.chapter2.t7; 

public class Run {

	public static void main(String[] args) {
		Task task=new Task();
		ThreadA a =new ThreadA(task);
		a.start();
		
		ThreadB b =new ThreadB(task);
		b.start();
	}

}


class ThreadB extends Thread{
	private Task task;
	public ThreadB(Task task) {
		super();
		this.task=task;
	}
	
	@Override 
	public void run() {
		super.run();
		task.doLongTimeTask();
	}
}

class ThreadA extends Thread{
	private Task task;
	public ThreadA(Task task) {
		super();
		this.task=task;
	}
	
	@Override 
	public void run() {
		task.doLongTimeTask();
	}
}

class Task {
	public void doLongTimeTask() {
		for (int i = 0; i < 100; i++) {
			System.out.println("nosynchronized threadName=" + Thread.currentThread().getName() + " i=" + (i + 1));
		}
		System.out.println("");
		synchronized (this) {
			for (int i = 0; i < 100; i++) {
				System.out.println("nosynchronized threadName=" + Thread.currentThread().getName() + " i=" + (i + 1));
			}
		}
	}
}